import 'dart:typed_data';

import 'package:bluetooth_protocols_parser_plugin/src/lorin/realtime/error/v12s_realtime_error.dart';
import 'package:bluetooth_protocols_parser_plugin/src/lorin/realtime/info/v12s_realtime_info.dart';
import 'package:bluetooth_protocols_parser_plugin/src/lorin/realtime/status/v12s_realtime_status.dart';
import 'package:bluetooth_protocols_plugin/library.dart';

// V12s 所有实时信息
class V12sRealtimeAllInfo extends LorinRealtimeAllInfo<V12sRealtimeInfo,
    V12sRealtimeStatus, V12sRealtimeError> {
  late Uint8List infoBytes;
  late Uint8List errorBytes;
  late Uint8List statusBytes;

  V12sRealtimeAllInfo.fromBytes(Uint8List bytes) : super.fromBytes(bytes) {
    int index = 0;
    infoBytes = bytes.sublist(index, index + 74);
    index += 74;
    statusBytes = bytes.sublist(index, index + 4);
    index += 4;
    errorBytes = bytes.sublist(index, index + 8);
  }

  @override
  V12sRealtimeError get error => V12sRealtimeError.fromBytes(errorBytes);

  @override
  V12sRealtimeInfo get info => V12sRealtimeInfo.fromBytes(infoBytes);

  @override
  V12sRealtimeStatus get status => V12sRealtimeStatus.fromBytes(statusBytes);

  @override
  int dataIntValue() {
    return info.dataIntValue() + error.dataIntValue() + status.dataIntValue();
  }

  @override
  int dataLength() {
    return info.dataLength() + error.dataLength() + status.dataLength();
  }

  @override
  int get minLength => info.minLength + error.minLength + status.minLength;

  @override
  Uint8List toBytes() {
    return Uint8List.fromList(
        [...info.toBytes(), ...error.toBytes(), ...status.toBytes()]);
  }

  @override
  Map<String, dynamic> toMap() {
    return {
      'info': info.toMap(),
      'error': error.toMap(),
      'status': status.toMap(),
      'version': '$runtimeType',
    };
  }
}
